package com.action.log;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.config.SystemGlobals;
import com.sql.DBFactory;

public class DelLogType extends HttpServlet {

	private static final long serialVersionUID = 1L;

	private Connection conn = null;

	private PreparedStatement pstmt = null;

	private Statement stmt = null;

	private ResultSet rs = null;

	private String delSQL = null;

	private static final Log log = LogFactory.getLog(DelLogType.class);

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String contentType = SystemGlobals.getValue("contentType");
		PrintWriter out = response.getWriter();
		response.setContentType(contentType);
		if (request.getParameter("logtypeid") != null) {
			String logNos[] = request.getParameterValues("logtypeid");
			delSQL = "delete from log_type where logtype_id=?";
			try {
				conn = DBFactory.getConnection();
				for (int i = 0; i < logNos.length; i++) {

					stmt = conn.createStatement();
					pstmt = conn.prepareStatement(delSQL);
					pstmt.setInt(1, Integer.parseInt((logNos[i])));
					pstmt.executeUpdate();
					pstmt.close();
				}
				rs.close();
				stmt.close();
				conn.close();
				out
						.print("<script>alert(\"删除日志分类成功\");window.location=\"user/loglist.jsp\";</script>");
			} catch (Exception e) {
				log.error(e.toString());
			}
		}
		out.close();
	}

}
